/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package se.jtech.jdf.mimetool.beans;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.BodyPart;
import javax.mail.MessagingException;
import org.jdesktop.application.AbstractBean;

/**
 *
 * @author awxva
 */
public class BodyPartBean extends AbstractBean {

    private BodyPart bodyPart;

    public BodyPartBean() {
        super();
    }

    public BodyPartBean(BodyPart bodyPart) {
        this();
        this.bodyPart = bodyPart;
    }

    public void setBodyPart(BodyPart bodyPart) {
        this.bodyPart = bodyPart;
    }

    public String getFileName() {
        try {
            return bodyPart.getFileName();
        } catch (MessagingException ex) {
            Logger.getLogger(BodyPartBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public long getSize() {
        try {
            return bodyPart.getSize();
        } catch (MessagingException ex) {
            Logger.getLogger(BodyPartBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return -1;
    }

    public String getCID() {
        try {
            String[] cid = bodyPart.getHeader("Content-ID");
            if (cid != null && cid.length > 0) {
                return cid[0];
            }
        } catch (MessagingException ex) {
            Logger.getLogger(BodyPartBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public String getContentType() {
        try {
            return bodyPart.getContentType();
        } catch (MessagingException ex) {
            Logger.getLogger(BodyPartBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public BodyPart getBodyPart() {
        return bodyPart;
    }
}
